package com.itcast.discover.Controller;

import com.itcast.discover.service.DiscoverCService;
import com.pojo.discover.pojo.DiscoverC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
* 发现分类
* */
@RestController
public class DiscoverCController {
    @Autowired
    private DiscoverCService discoverCService;

    /*
    * 查看所有的分类
    * */
    @GetMapping("/discoverC/findAll")
    public List<DiscoverC> findDiscoverCAll(){
        List<DiscoverC> discoverCAll = discoverCService.findDiscoverCAll();
        return discoverCAll;

    }
    /*
    * 根据id更改分类信息
    * */
    @GetMapping("/discoverC/update")
    public void  updateDiscoverC(@RequestBody DiscoverC discoverC){
        discoverCService.updateDiscoverC(discoverC);
    }

    /*
    * 删除分类
    * */
    @GetMapping("discoverC/delete/{cid}")
    public String deleteDiscoverCBy(@PathVariable("cid")Integer cid)
    {
        Boolean ifDel = discoverCService.deleteByCid(cid);
        if(ifDel){
            return "有分类关联，不可直接删除！";
        }
        return "删除成功";
    }

    /*
    * 新增分类
    * */
    @GetMapping("discoverC/insert")
    public void insertDiscoverC(@RequestBody DiscoverC discoverC){
        discoverCService.insertDiscoverC(discoverC);
    }
}
